<?php

namespace App\Http\Controllers\Admin;

use App\Models\Cash;
use App\Models\SystemConfig;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Pagination\Paginator;

class CashController extends Controller
{
    /**提现列表
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function index(Cash $cashModel)
    {
        $data['list'] = $cashModel -> cash_list();
        return view('admin.cash.index',$data);
    }

    /**提现操作
     * @param Request $request
     * @param Cash $cashModel
     */
    public function docash(Request $request,Cash $cashModel,$cash_id)
    {
        if($cashModel->cash($cash_id)){
            return redirect()->back()->with('success','提现处理成功');
        }
        return redirect()->back()->with('error','提现处理失败，请稍后再试');
    }

    /**提现配置页面
     * @param Cash $cashModel
     */
    public function set_index(Cash $cashModel)
    {
        $data['config_arr'] = [
            'cash_min_money' => filter_empty(SystemConfig::getConfValByConfKey('cash_min_money'),'conf_val') , //充值优惠满多少金额
            'cash_service_charge'     => filter_empty(SystemConfig::getConfValByConfKey('cash_service_charge'),'conf_val') ,     //充值满足recharge_money数量后赠送多少金额
        ];
        return view('admin.cash.set_index',$data);
    }

    /**保存提现配置选项
     * @param Request $request
     * @return \Illuminate\Http\RedirectResponse
     */
    public function save_set(Request $request)
    {
        $data = $request -> input('Cash');
        foreach($data as $key => $val)
        {
            $val = isset($val)  ? $val : '';
            SystemConfig::modifyValByConfKey($key,$val);
        }
        return redirect()->back()->with('success','保存成功');
    }




}
